package de.wepner.texteditor;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import de.wepner.texteditor.command.AboutCommand;
import de.wepner.texteditor.command.ExitCommand;
import de.wepner.texteditor.command.LoadFileCommand;
import de.wepner.texteditor.command.NewFileCommand;
import de.wepner.texteditor.command.RedoCommand;
import de.wepner.texteditor.command.SaveCommand;
import de.wepner.texteditor.command.UndoCommand;
import de.wepner.texteditor.model.EditorData;
import de.wepner.texteditor.ui.EditorWindow;


public class Main {
    
    public static void main(String[] args) {
        
        JFrame.setDefaultLookAndFeelDecorated(true);
        JDialog.setDefaultLookAndFeelDecorated(true);
        try {
//            Metal: javax.swing.plaf.metal.MetalLookAndFeel
//            Nimbus: javax.swing.plaf.nimbus.NimbusLookAndFeel
//            CDE/Motif: com.sun.java.swing.plaf.motif.MotifLookAndFeel
//            Windows: com.sun.java.swing.plaf.windows.WindowsLookAndFeel
//            Windows Classic: com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel
//            UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }
        
        EditorData data = new EditorData();
        data.commands.setCommand(EditorData.NEW_FILE_COMMAND, new NewFileCommand(data));
        data.commands.setCommand(EditorData.UNDO_COMMAND, new UndoCommand(data));
        data.commands.setCommand(EditorData.REDO_COMMAND, new RedoCommand(data));
        EditorWindow window = new EditorWindow(data);
        data.commands.setCommand(EditorData.LOAD_FILE_COMMAND, new LoadFileCommand(data, window));
        data.commands.setCommand(EditorData.SAVE_FILE_COMMAND, new SaveCommand(data, window, false));
        data.commands.setCommand(EditorData.SAVE_FILE_AS_COMMAND, new SaveCommand(data, window, true));
        data.commands.setCommand(EditorData.EXIT_APPLICATION_COMMAND, new ExitCommand(data, window));
        data.commands.setCommand(EditorData.ABOUT_COMMAND, new AboutCommand(window));
        window.setLocationByPlatform(true);
        window.setVisible(true);
    }
}
